package b.l.a;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import b.l.a.i.i;
import java.util.Objects;

/* compiled from: DialogFragment */
public class b extends Fragment implements OnCancelListener, OnDismissListener {
    public Handler W;
    public Runnable X = new a();
    public int Y = 0;
    public int Z = 0;
    public boolean b0 = true;
    public boolean c0 = true;
    public int d0 = -1;
    public Dialog e0;
    public boolean f0;
    public boolean g0;
    public boolean h0;

    /* compiled from: DialogFragment */
    public class a implements Runnable {
        public void run() {
            b bVar = b.this;
            Dialog dialog = bVar.e0;
            if (dialog != null) {
                bVar.onDismiss(dialog);
            }
        }
    }

    public void C(Bundle bundle) {
        this.E = true;
        if (this.c0) {
            View view = this.G;
            if (view != null) {
                if (view.getParent() == null) {
                    this.e0.setContentView(view);
                } else {
                    throw new IllegalStateException("DialogFragment can not be attached to a container view");
                }
            }
            FragmentActivity e = e();
            if (e != null) {
                this.e0.setOwnerActivity(e);
            }
            this.e0.setCancelable(this.b0);
            this.e0.setOnCancelListener(this);
            this.e0.setOnDismissListener(this);
            if (bundle != null) {
                bundle = bundle.getBundle("android:savedDialogState");
                if (bundle != null) {
                    this.e0.onRestoreInstanceState(bundle);
                }
            }
        }
    }

    public void D(Context context) {
        super.D(context);
        if (!this.h0) {
            this.g0 = false;
        }
    }

    public void E(Bundle bundle) {
        super.E(bundle);
        this.W = new Handler();
        this.c0 = this.w == 0;
        if (bundle != null) {
            this.Y = bundle.getInt("android:style", 0);
            this.Z = bundle.getInt("android:theme", 0);
            this.b0 = bundle.getBoolean("android:cancelable", true);
            this.c0 = bundle.getBoolean("android:showsDialog", this.c0);
            this.d0 = bundle.getInt("android:backStackId", -1);
        }
    }

    public void J() {
        this.E = true;
        Dialog dialog = this.e0;
        if (dialog != null) {
            this.f0 = true;
            dialog.setOnDismissListener(null);
            this.e0.dismiss();
            if (!this.g0) {
                onDismiss(this.e0);
            }
            this.e0 = null;
        }
    }

    public void K() {
        this.E = true;
        if (!this.h0 && !this.g0) {
            this.g0 = true;
        }
    }

    public LayoutInflater L(Bundle bundle) {
        if (!this.c0) {
            return super.L(bundle);
        }
        Dialog n0 = n0(bundle);
        this.e0 = n0;
        String str = "layout_inflater";
        if (n0 == null) {
            return (LayoutInflater) this.s.b.getSystemService(str);
        }
        int i = this.Y;
        if (!(i == 1 || i == 2)) {
            if (i == 3) {
                n0.getWindow().addFlags(24);
            }
            return (LayoutInflater) this.e0.getContext().getSystemService(str);
        }
        n0.requestWindowFeature(1);
        return (LayoutInflater) this.e0.getContext().getSystemService(str);
    }

    public void Q(Bundle bundle) {
        Dialog dialog = this.e0;
        if (dialog != null) {
            Bundle onSaveInstanceState = dialog.onSaveInstanceState();
            if (onSaveInstanceState != null) {
                bundle.putBundle("android:savedDialogState", onSaveInstanceState);
            }
        }
        int i = this.Y;
        if (i != 0) {
            bundle.putInt("android:style", i);
        }
        i = this.Z;
        if (i != 0) {
            bundle.putInt("android:theme", i);
        }
        boolean z = this.b0;
        if (!z) {
            bundle.putBoolean("android:cancelable", z);
        }
        z = this.c0;
        if (!z) {
            bundle.putBoolean("android:showsDialog", z);
        }
        i = this.d0;
        if (i != -1) {
            bundle.putInt("android:backStackId", i);
        }
    }

    public void R() {
        this.E = true;
        Dialog dialog = this.e0;
        if (dialog != null) {
            this.f0 = false;
            dialog.show();
        }
    }

    public void S() {
        this.E = true;
        Dialog dialog = this.e0;
        if (dialog != null) {
            dialog.hide();
        }
    }

    public void m0(boolean z, boolean z2) {
        if (!this.g0) {
            this.g0 = true;
            this.h0 = false;
            Dialog dialog = this.e0;
            if (dialog != null) {
                dialog.setOnDismissListener(null);
                this.e0.dismiss();
                if (!z2) {
                    if (Looper.myLooper() == this.W.getLooper()) {
                        onDismiss(this.e0);
                    } else {
                        this.W.post(this.X);
                    }
                }
            }
            this.f0 = true;
            if (this.d0 >= 0) {
                h a0 = a0();
                int i = this.d0;
                i iVar = (i) a0;
                if (i >= 0) {
                    iVar.S(new i(null, i, 1), false);
                    this.d0 = -1;
                } else {
                    throw new IllegalArgumentException(c.b.a.a.a.A("Bad id: ", i));
                }
            }
            a aVar = new a((i) a0());
            aVar.g(this);
            if (z) {
                aVar.k();
            } else {
                aVar.j();
            }
        }
    }

    public Dialog n0(Bundle bundle) {
        throw null;
    }

    public void o0(boolean z) {
        this.b0 = z;
        Dialog dialog = this.e0;
        if (dialog != null) {
            dialog.setCancelable(z);
        }
    }

    public void onCancel(DialogInterface dialogInterface) {
    }

    public void onDismiss(DialogInterface dialogInterface) {
        if (!this.f0) {
            m0(true, true);
        }
    }

    public void p0(h hVar, String str) {
        this.g0 = false;
        this.h0 = true;
        i iVar = (i) hVar;
        Objects.requireNonNull(iVar);
        a aVar = new a(iVar);
        aVar.f(0, this, str, 1);
        aVar.j();
    }
}
